package com.service.apply;

import com.dao.BaseDao;
import com.dao.apply.ApplyDao;
import com.dao.apply.ApplyDaoImpl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.BitSet;
import java.util.List;

public class ApplyServiceImpl implements ApplyService{

    private final ApplyDao applyDao;
    public ApplyServiceImpl(){
        applyDao = new ApplyDaoImpl();
    }


    @Override
    public List<Object> getSearchApplyList(String applyName) {
        Connection connection = null;
        List<Object> applys = null;


        try {
            connection = BaseDao.getConnection();
            applys = applyDao.getSearchApplyList(connection, applyName);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }


        return applys;
    }

    @Override
    public List<Object> getUserApplyList(int userId) {
        Connection connection = null;
        List<Object> apply = null;

        try {
            connection = BaseDao.getConnection();
            apply = applyDao.getUserApplyList(connection, userId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return apply;
    }

    @Override
    public int UserApplyListDel(int applyId) {
        Connection connection = null;
        int flag = 0;
        connection = BaseDao.getConnection();
        try {
            flag = applyDao.UserApplyListDel(connection,applyId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public int ApplyAdd(int userId, String applyName, String applyAddress, String applyExplain) {
        Connection connection = null;
        int flag = 0;
        connection = BaseDao.getConnection();
        try {
            flag = applyDao.ApplyAdd(connection,userId,applyName,applyAddress,applyExplain);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }
}
